<?php

class Application_Model_DbTable_AccountDetail extends Zend_Db_Table_Abstract {

    protected $_name = 'account_detail';
	
	public function getAccountDetail($id){
        $row = $this->fetchRow("id=".$id);
        return $row;
	}
	
	public function getAccountDetailOfAccount($accountId, $purchaseType){
		
		if($purchaseType != 0)
			$rows = $this->fetchAll("accountId=".$accountId." and purchaseType=".$purchaseType);
		else
			$rows = $this->fetchAll("accountId=".$accountId);
		return $rows;
	}
	
	public function getAccountDetailList(){
		$row = $this->fetchAll();
		return $row;
	}	
		
	public function createAccountDetail($accountId, $actionType, $amount, $createTime, $purchaseId, $purchaseType, $purchaseNumber){
		$row = $this->createRow();
		$row->accountId = $accountId;
		$row->actionType = $actionType;
		$row->amount = $amount;
		$row->createTime = $createTime;
		$row->purchaseId = $purchaseId;
		$row->purchaseType = $purchaseType;
		$row->purchaseNumber = $purchaseNumber;
		$row->save();
		return $row;
	}

	public function updateAccountDetail($accountId, $purchaseId, $purchaseType){
		$row = $this->fetchRow("accountId=".$accountId." and purchaseId=".$purchaseId." and purchaseType=".$purchaseType);
		$row->flag = 2;		
		$row->save();
		return $row;
	}
}
